package com.yw.smartcityforjava.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.yw.smartcityforjava.App;
import com.yw.smartcityforjava.R;

import java.net.URL;
import java.util.concurrent.ExecutionException;

public class NewsDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);
        Toolbar toolbar = findViewById(R.id.toolbar);
        TextView titleTv = toolbar.findViewById(R.id.titleTv);
        titleTv.setText("新闻详情");
        TextView titleView = findViewById(R.id.title);
        ImageView imageView = findViewById(R.id.imgIv);
        TextView commentNumTv = findViewById(R.id.commentNumTv);
        TextView publicTimeTv = findViewById(R.id.publicTimeTv);
        WebView webView = findViewById(R.id.webview);


        String title = getIntent().getStringExtra("title");
        String content = getIntent().getStringExtra("content");
        String img = getIntent().getStringExtra("img");
        int commentNum = getIntent().getIntExtra("commentNum",0);
        String publicTime = getIntent().getStringExtra("publicTime");
        titleView.setText(title);

        webView.loadDataWithBaseURL(App.baseUrl, content, "text/html", "utf-8", null);
        Glide.with(this).load(App.baseUrl+img).into(imageView);
        commentNumTv.setText("评论数: "+commentNum);
        publicTimeTv.setText("发布时间: "+publicTime);

        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
}